package cn.zhz.springdoc.console.controller;

import cn.hutool.core.util.StrUtil;
import cn.zhz.springdoc.console.mapper.IOpenApiMapper;
import cn.zhz.springdoc.console.po.OpenApiPo;
import cn.zhz.springdoc.console.vo.GroupVo;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ZHZ
 * @since 2022-11-15
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/group")
public class GroupController {


    private final IOpenApiMapper iOpenApiMapper;

    @GetMapping("/list")
    public List<GroupVo> list(@RequestParam(required = false) String projectName) {

        return iOpenApiMapper.selectList(Wrappers.lambdaQuery(OpenApiPo.class)
                .select(OpenApiPo::getGroupName).eq(StrUtil.isNotBlank(projectName),OpenApiPo::getProjectName,projectName))
                .stream().map(apiPo -> new GroupVo(apiPo.getGroupName()))
                .distinct().collect(Collectors.toList());
    }
}
